﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoffeeTeaTrading.Core.Infrastructure.Utils
{
    public class RuleViolation : IRuleViolation
    {
        public string ErrorMessage { get; private set; }

        /// <summary>
        /// An object wich was validated.
        /// </summary>
        public object ValidatedObject { get; private set; }

        public string PropertyName { get; private set; }

        /// <summary>
        /// Property is used as a 'rawValue' parameter in ValueProviderResult constructor.
        /// This object will be converted to string and will appear as previous value.
        /// </summary>
        public Object PreviousValue { get; private set; }

        /// <summary>
        /// Property is used as a 'attemptedValue' parameter in ValueProviderResult constructor.
        /// It looks like there should be string representation of PreviousValue
        /// </summary>
        public string AttemptedValue
        {
            get
            {
                return PreviousValue != null ? PreviousValue.ToString() : String.Empty;
            }
        }

        public RuleViolation(string errorMessage, object validatedObject, string propertyName, object previousValue)
        {
            if (validatedObject == null) throw new ArgumentNullException("validatedObject");
            if (propertyName == null) throw new ArgumentNullException("propertyName");

            ValidatedObject = validatedObject;
            ErrorMessage = errorMessage;
            PropertyName = propertyName;
            PreviousValue = previousValue;
        }
    }
}
